from elimination_game_bll import EliminationGameController
import copy


class EliminationGameView:
    """
     2048游戏界面
    """

    def __init__(self):
        self.__controller = EliminationGameController()

    def __display_list_map(self):
        """
            可视化二维列表
        """
        for r in range(len(self.__controller.list_map)):
            print("-----------------------------")
            for c in range(len(self.__controller.list_map[r])):
                print("|%2.d" % self.__controller.list_map[r][c], end=" ")
            print("|", end="\t")
            print()
        print("-----------------------------")

    @staticmethod
    def __select_menu():
        """
            确定两个交换的元素
        :return: （元素1，元素2）元素均为元组类型
        """
        tuple_start = tuple(input("请输入选定的元素:"))
        while True:
            tuple_end = tuple(input("请输入交换的元素:"))
            if tuple_end == tuple_start: continue
            for item in tuple_end:
                if item in tuple_start:
                    return tuple_start, tuple_end

    def __judge_move(self):
        """
            判断移动是否有效
        """
        while True:
            list_contrast = copy.deepcopy(self.__controller.list_map)
            self.__select_menu()
            if self.__controller.list_map != list_contrast:
                self.__controller.append_random_generation_number()
                break
            print("移动无效")
            self.__display_list_map()

    def main(self):
        """
            游戏函数调用
        """
        self.__controller.start_list_map()
        while True:
            self.__display_list_map()
            print(self.__select_menu())


if __name__ == '__main__':
    view = EliminationGameView()
    view.__display_list_map()
